package cn.fuxue.hrms.service.impl;

import cn.fuxue.hrms.common.base.AbstractService;
import cn.fuxue.hrms.common.dto.CvInfoShow;
import cn.fuxue.hrms.common.entity.CvBasicInfo;
import cn.fuxue.hrms.common.entity.CvInfo;
import cn.fuxue.hrms.mapper.CvMapper;
import cn.fuxue.hrms.service.CvService;
import cn.fuxue.hrms.service.process.CvEduExpProcessor;
import cn.fuxue.hrms.service.process.CvProjectExpProcessor;
import cn.fuxue.hrms.service.process.CvWorkExpProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class CvServiceImpl extends AbstractService<CvInfo,Integer> implements CvService {
    @Autowired
    CvMapper cvMapper;
    @Autowired
    CvEduExpProcessor cvEduExpProcessor;
    @Autowired
    CvProjectExpProcessor cvProjectExpProcessor;
    @Autowired
    CvWorkExpProcessor cvWorkExpProcessor;


    @Override
    public List<CvInfoShow> findCvInfo(String likename) {
        List<CvInfoShow> cvInfoShowList=cvMapper.findCvInfo(likename);
        for (CvInfoShow cvInfoShow:cvInfoShowList) {
            Integer userId=cvInfoShow.getUserId();
            Long workNumber=cvMapper.findWorkNumber(userId).get("workNumber");
            Integer eduBack=cvMapper.findEduBack(userId).get("eduBack");
            cvInfoShow.setWorkNumber(workNumber);
            cvInfoShow.setEduBack(eduBack);
        }
        return cvInfoShowList;
    }

    @Override
    public List<Map<String,Object>> findCvInfoById(Integer cv_id) {
        return cvMapper.findCvInfoById(cv_id);
    }




    @Override
    public Integer addOtherService(Map<String, Object> map) throws Exception {
        Integer cvId=(Integer)map.get("cvId");
        List<Map<String,Object>> education_token = (List<Map<String, Object>>) map.get("education_token");
        List<Map<String,Object>> work_token= (List<Map<String, Object>>) map.get("work_token");
        List<Map<String,Object>> project_token= (List<Map<String, Object>>) map.get("project_token");

//
        cvEduExpProcessor.setCvId(cvId);
        int edu=cvEduExpProcessor.process(education_token);
        cvWorkExpProcessor.setCvId(cvId);
        int work=cvWorkExpProcessor.process(work_token);
        cvProjectExpProcessor.setCvId(cvId);
        int pro=cvProjectExpProcessor.process(project_token);



        return pro+edu+work;
    }






    @Autowired
    public void setBaseMapper() {
        super.setBaseMapper(cvMapper);
    }



}
